//////////////////////////////////////////////////////////////////////////////////
//	 Copyright 2011 by Yosef Grabivker, ryuho@homenetworksoft.com
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//////////////////////////////////////////////////////////////////////////////////

#ifndef _PING_TAB_YG_H__
#define _PING_TAB_YG_H__

#include "pingengine.h"

class CPingTab: public wxPanel, public ILoggable, public ITabedPageUI, public CPingEngineObserver
{
public:
								CPingTab(class wxWindow* pParent);
	virtual						~CPingTab(void);

	//ILoggable
	virtual wxString			GetLog();

	//ITabedPageUI
	virtual cTabPageID			GetTabID()						{ return cTabIDPing; }
	virtual bool				IsTimeSelectorSupported()		{ return true;		 }
	virtual time_t				GetTimeInterval()				{ return m_tInt;	 }
	virtual void				SetTimeInterval(size_t tInt);

	//List control
	long						GetItemCount(wxWindowID id=wxID_ANY)
	{
		return m_list.size();
	}

	wxString					GetItemText(long item, long column, wxWindowID id=wxID_ANY);

	int							GetItemColumnImage(long item, long column, wxWindowID id=wxID_ANY);
	
	virtual int					GetItemImage(long item, wxWindowID id=wxID_ANY);

	class wxListItemAttr*		GetItemAttr(long item, wxWindowID id);
	

	bool						OnDropText(wxCoord x, wxCoord y, const wxString& data) { return false; }
	void						OnDragDropFinished( wxWindowID id, wxDragResult result) {}
	void						OnContextMenu(long id, long col) {}

	static wxString				GetStatusString(cPingStatus status);
	static wxString				GetActionString(cPingFailedAction status);

	//CPingEngineObserver
	virtual void OnPingResult(int nItem, const PINGRESULT& result);

protected:
	void						OnProcessPingEvent(wxCommandEvent& event);

	void						OnAdd(wxCommandEvent& ev);
	void						OnEdit(wxCommandEvent& ev);
	void						OnRemove(wxCommandEvent& ev);

	void						OnAddUI(wxUpdateUIEvent& ev);
	void						OnEditUI(wxUpdateUIEvent& ev);
	void						OnRemoveUI(wxUpdateUIEvent& ev);
	DECLARE_EVENT_TABLE()

	bool						IsSelected();

	PINGDATALIST				m_list;

protected:
	wxString					FieldToString( int iFieldID, PingData& entry, int iID);
	void						UpdateImageItem( int item );
	void						LoadData();
	void						DispatchEntry(PingData& entry);
	void						DoScriptEvent( const PingData& entry );

private:
	time_t						m_tInt;
	class CLevelGraph*			m_pLinePing;
	class CLevelGraph*			m_pLineJitter;
	class wxListCtrl*			m_pList;

	class wxButton*				m_pbtnAdd;
	class wxButton*				m_pbtnEdit;
	class wxButton*				m_pbtnRemove;

	class wxImageList*			m_pImageList;

	CPingEngine					m_ping;

	wxCriticalSection			m_csData;
};

struct CPingDataDlg: public wxDialog
{
								CPingDataDlg(const wxString& strTitle, class wxWindow* pParent, PingData& data);
protected:
	void						OnOk(wxCommandEvent& ev);
	void						OnOkUI(wxUpdateUIEvent& ev);
	void						OnFileUI(wxUpdateUIEvent& ev);
	void						OnAskFilePath(wxCommandEvent& ev);
	DECLARE_EVENT_TABLE()


private:
	class wxTextCtrl*			m_pHost;
	class wxSpinCtrl*			m_pInterval;
	class wxSpinCtrl*			m_pActionCnt;
	class wxComboBox*			m_pAction;
	class wxComboBox*			m_pStatus;
	class wxBoxSizer*			m_pFileSizer;
	class wxTextCtrl*			m_pFilePath;
	class wxColourPickerCtrl*	m_pColor;

	PingData&					m_data;
};

#endif //_PING_TAB_YG_H__